package com.jianglin.controller;

import com.github.pagehelper.PageInfo;
import com.jianglin.model.PropertyType;
import com.jianglin.service.IPropertyTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
/**
 *
 *
 * @author liyijia
 */
@Api(tags = {"物业费类型管理"})
@CrossOrigin(origins="http://localhost:5500")
@RestController
@RequestMapping("/propertyType")
public class PropertyTypeController {
    @Resource
    private IPropertyTypeService propertyTypeService;
    @RequestMapping("/queryAll")
    public List<PropertyType> queryList(){
        return propertyTypeService.findAll();
    }

    @ApiOperation(value = "新增")
    @PostMapping()
    public int add(@RequestBody PropertyType propertyType){
        return propertyTypeService.add(propertyType);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("{id}")
    public int delete(@PathVariable("id") Long id){
        return propertyTypeService.delete(id);
    }

    @ApiOperation(value = "更新")
    @PutMapping()
    public int update(@RequestBody PropertyType propertyType){
        return propertyTypeService.updateData(propertyType);
    }

    @ApiOperation(value = "查询分页数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码"),
            @ApiImplicitParam(name = "pageCount", value = "每页条数")
    })

    @GetMapping
    public PageInfo<PropertyType> findListByPage(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        return propertyTypeService.findListByPage(page, pageSize);
    }

    @ApiOperation(value = "id查询")
    @GetMapping("{id}")
    public PropertyType findById(@PathVariable Long id){
        return propertyTypeService.findById(id);
    }

}
